home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Found / BCCollec / Tools / Search / BCSearcT.cpp < prev    next >
Encoding:
Text File  |  1994-04-21  |  1.9 KB  |  80 lines  |  [TEXT/MPS ]

  1. //  The C++ Booch Components (Version 2.1)
  2. //  (C) Copyright 1990-1993 Grady Booch. All Rights Reserved.
  3. //
  4. //  Restricted Rights Legend
  5. //  Use, duplication, or disclosure is subject to restrictions as set forth 
  6. //  in subdivision (c)(1)(ii) of the Rights in Technical Data and Computer 
  7. //  Software clause at DFARS 252.227-7013. 
  8. //
  9. //  BCSearcT.cpp
  10. //
  11. //  This file contains the definitions for the tree searching tools.
  12.  
  13. #include "BCSearcT.h"
  14.  
  15. template<class Tree>
  16. BC_TBinaryTreeSearch<Tree>::BC_TBinaryTreeSearch() {}
  17.   
  18. template<class Tree>
  19. BC_TBinaryTreeSearch<Tree>::~BC_TBinaryTreeSearch() {}
  20.  
  21. template<class Tree>
  22. BC_Boolean BC_TBinaryTreeSearch<Tree>::
  23.   PreOrder(const Tree& target, BC_Boolean (*process)(const Tree&))
  24. {
  25.   Tree subtree;
  26.   if (!target.IsNull()) {
  27.     if (!process(target))
  28.       return 0;
  29.     subtree = target;
  30.     subtree.LeftChild();
  31.     if (!PreOrder(subtree, process))
  32.       return 0;
  33.     subtree = target;
  34.     subtree.RightChild();
  35.     if (!PreOrder(subtree, process))
  36.       return 0;
  37.   }
  38.   return 1;
  39. }
  40.  
  41. template<class Tree>
  42. BC_Boolean BC_TBinaryTreeSearch<Tree>::
  43.   InOrder(const Tree& target, BC_Boolean (*process)(const Tree&))
  44. {
  45.   Tree subtree;
  46.   if (!target.IsNull()) {
  47.     subtree = target;
  48.     subtree.LeftChild();
  49.     if (!InOrder(subtree, process))
  50.       return 0;
  51.     if (!process(target))
  52.       return 0;
  53.     subtree = target;
  54.     subtree.RightChild();
  55.     if (!InOrder(subtree, process))
  56.       return 0;
  57.   }
  58.   return 1;
  59. }
  60.  
  61. template<class Tree>
  62. BC_Boolean BC_TBinaryTreeSearch<Tree>::
  63.   PostOrder(const Tree& target, BC_Boolean (*process)(const Tree&))
  64. {
  65.   Tree subtree;
  66.   if (!target.IsNull()) {
  67.     subtree = target;
  68.     subtree.LeftChild();
  69.     if (!PostOrder(subtree, process))
  70.       return 0;
  71.     subtree = target;
  72.     subtree.RightChild();
  73.     if (!PostOrder(subtree, process))
  74.       return 0;
  75.     if (!process(target))
  76.       return 0;
  77.   }
  78.   return 1;
  79. }
  80.